<?php

/** 
 * 收藏
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

namespace Common\Service;

Class FavourService extends BaseService
{
	/**
	 	*type:   默认0  (视频，比赛 )
	 	*uid :   用户UID
	 	*video_id:  视频ID 	
		*create_time:收藏的时间	 
	 */

	//add auto action by susy.liang
	const ERROR_VIDEO = '目标对象不存在';
	const ERROR_TYPE = '目标类型不存在';
	const ERROR_USER = '用户信息错误';

	// 类型
	const TYPE_VIDEO = 0;	//视频
	const TYPE_MATCH  = 1;   // 比赛  

	protected $_validate = array(
		array('video_id', 'require', self::ERROR_VIDEO, self::MUST_VALIDATE , 'regex', self::MODEL_BOTH),
		array('type', 'require', self::ERROR_TYPE, self::MUST_VALIDATE , 'regex', self::MODEL_BOTH),
		array('uid', 'require', self::ERROR_USER, self::MUST_VALIDATE , 'regex', self::MODEL_BOTH),
		);

	protected $_auto = array(
        array('uid', 'intval', self::MODEL_BOTH, 'function'),
        array('video_id', 'intval', self::MODEL_BOTH, 'function'),
         array('type', 'intval', self::MODEL_BOTH, 'function'),
        array('create_time', NOW_TIME, self::MODEL_INSERT),
    );  
	//end
	
	public function countByVideo($video_id)
	{
		return $this->where(['video_id' => (int)$video_id])->count();
	}

}